package com.qlmjx.sevalopos.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qlmjx.sevalopos.Bean.OrederBean;
import com.qlmjx.sevalopos.R;
import com.qlmjx.sevalopos.utils.ViewHolder;
import com.universal.frame.generalutils.DecimalUtil;

import java.util.List;

/**
 * Created by sa on 2018/7/20.
 */



public class OrderPayAdapter extends BaseAdapter {

    private Context context;
    private List<OrederBean> list;


    public OrderPayAdapter(Context context, List<OrederBean> list){
        this.context = context;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public OrederBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        OrederBean bean = getItem(position);
        if(view == null){
            view = View.inflate(context, R.layout.item_orderpay,null);
        }
        TextView tv_name = ViewHolder.get(view, R.id.tv_name);
        tv_name.setText(bean.PART_NAME);
        TextView tv_price = ViewHolder.get(view, R.id.tv_price);
        tv_price.setText("￥" + bean.PART_DISCOUNT_PRICE);
        TextView tv_num = ViewHolder.get(view, R.id.tv_num);
        tv_num.setText(bean.PART_NUM);
        TextView tv_total = ViewHolder.get(view, R.id.tv_total);
        tv_total.setText("￥" + DecimalUtil.strRound( Integer.parseInt(bean.PART_NUM)*convertToDouble(bean.PART_DISCOUNT_PRICE, 0.0f) + "",2));

        return view;
    }
    //把String转化为double
    public static double convertToDouble(String number, double defaultValue) {
        if (TextUtils.isEmpty(number)) {
            return defaultValue;
        }
        try {
            return Double.parseDouble(number);
        } catch (Exception e) {
            return defaultValue;
        }

    }
}
